package com.qianfeng.mapper;


import com.qianfeng.entry.YQAddEntry;
import com.qianfeng.entry.YQComEntry;
import com.qianfeng.entry.YQMapEntry;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 疫情业务接口
 */
@Mapper
public interface YQMapper {

    /**
     * 疫情分布地图接口
     * @return
     * 2020-02-18
     * 2020-02-25
     */
    @Select("SELECT\n" +
            "ry.province province,\n" +
            "SUM(ry.confirm_num) confirm_cnt\n" +
            "FROM report_yq ry\n" +
            "WHERE ry.dt >= #{startDate}\n" +
            "AND ry.dt <= #{endDate}\n" +
            "GROUP BY ry.province\n" +
            ";")
    public List<YQMapEntry> mapYiQings(@Param("startDate") String startDate,
                                       @Param("endDate") String endDate);


    /**
     * 疫情新增(默认查询是包含当天的前10天数据)
     * @return
     */
    @Select("select\n" +
            "ry.dt dt,\n" +
            "SUM(ry.confirm_num) confirms,\n" +
            "SUM(ry.possible_num) possibels\n" +
            "FROM report_yq ry\n" +
            "WHERE ry.dt BETWEEN DATE_SUB(CURDATE(), INTERVAL 765 DAY) AND CURRENT_DATE()\n" +
            "GROUP BY ry.dt\n" +
            "ORDER BY ry.dt ASC;")
    public List<YQAddEntry> addYiQings(@Param("interval") int interval);


    /**
     * 全国新增确诊和湖北新增确诊对比(默认查询是包含当天的前10天数据)
     * @return
     */
    @Select("select\n" +
            "ry.dt dt,\n" +
            "SUM(ry.confirm_num) all_confirms,\n" +
            "SUM(CASE ry.province WHEN ('湖北') THEN ry.confirm_num ELSE 0 END) confirms\n" +
            "FROM report_yq ry\n" +
            "WHERE ry.dt BETWEEN DATE_SUB(CURDATE(), INTERVAL 765 DAY) AND CURRENT_DATE()\n" +
            "GROUP BY ry.dt\n" +
            "ORDER BY ry.dt ASC\n" +
            ";")
    public List<YQComEntry> addComYiQings(int interval);
}
